`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    21:17:29 03/28/2014 
// Design Name: 
// Module Name:    addrcalc 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////


module backaddr_calc (Xpos,
							hcounter, 
							vcounter,
							blank,
							addra,
							Xposnext,
							Xposnext1,
							Xposnext2);
	
	input signed [10:0] Xpos, 
							  Xposnext,
							  Xposnext1,
							  Xposnext2;
	
	input               blank;
	input signed [10:0] hcounter,
							vcounter;
	output reg [14:0] addra;
	
		always @(hcounter,vcounter)
		begin
	
								if(~blank)begin
								if(hcounter>=Xpos && hcounter<Xpos+235 && vcounter>=342 && vcounter<479)
										begin
												addra= (hcounter-Xpos)+(vcounter-342)*235;
										end
								else if(hcounter>=Xposnext && hcounter<Xposnext+235 && vcounter>=342 && vcounter<479)
										begin	
												addra= (hcounter-Xposnext)+(vcounter-342)*235;
										end
								else if( hcounter>=Xposnext1 && hcounter<Xposnext1+235 && vcounter>=342 && vcounter<479)
										begin
												addra= (hcounter-Xposnext1)+(vcounter-342)*235;
										end
								else if( hcounter>=Xposnext2 && hcounter<Xposnext2+190 && vcounter>=342 && vcounter<479)
										begin
												addra= (hcounter-Xposnext2)+(vcounter-342)*235;
										end
								else
										begin
												addra=0;
										end
								end
								else 
										begin
								addra=0;
										end
	end
	
	
	
	
	
	
	
	
	
	
		
		
endmodule

